﻿@model OrderSystem.Controllers.ViewModel
@{
    ViewBag.Title = "Analysing orders";

    string preferableDeliveryDate = "";
    if (Model.OrderInfo.PreferableDeliveryDate != null)
    {
        preferableDeliveryDate = ((DateTime)Model.OrderInfo.PreferableDeliveryDate).ToShortDateString();
    }

    string orderingDate = Model.OrderInfo.DateOfOrdering.ToShortDateString();

    string disabled = ViewBag.OrderDisabled ? "disabled=\"disabled\"" : "";
        
    var displayLines = new List<SelectListItem>(new [] {
    new SelectListItem { Text = @"show 10 lines", Value="10" },
    new SelectListItem { Text = @"show 15 lines", Value="15" }, 
    new SelectListItem { Text = @"show 20 lines", Value="20" }, 
    new SelectListItem { Text = @"show 25 lines", Value="25" } });

    WebGrid itemsGrid = new WebGrid
        (
           Model.OrderedItems,
           canPage: true,
           canSort: true,
           rowsPerPage: 5
        );
        
}

@using (Html.BeginForm())
{
    <p>
        This page is appointed for analysing costumer orders and perform ordering
    </p>
    <fieldset>
        <legend align="left" style="font-weight: bold"> Items Selection </legend>
        <div align="right">
        @Html.DropDownList("showLines", displayLines, new { onchange = "@s=this.value" })
        </div>
        <div align="center">
            <p>
        @itemsGrid.GetHtml(columns: itemsGrid.Columns(
        itemsGrid.Column("ItemNumber", "Item Number"),
        itemsGrid.Column("ItemName", "Item Name"),
        itemsGrid.Column("ItemDescription", "Item Description"),
        itemsGrid.Column("Dimension"),
        itemsGrid.Column("Price"),
        itemsGrid.Column("Quantity"),
        itemsGrid.Column("PricePerLine", "Price per Line")
                                 ),
                             tableStyle: "webgrid",
                             headerStyle: "webgrid-header",
                             footerStyle: "webgrid-footer",
                             alternatingRowStyle: "webgrid-alternating-row",
                             selectedRowStyle: "webgrid-selected-row",
                             rowStyle: "webgrid-row-style"
               )
            </p>
        </div>
    </fieldset>
    <fieldset>
        <legend align="left" style="font-weight: bold;">Totals </legend>
        <table cellspacing="20" align="left">
            <tr>
                <td>
                    @Html.Label("Costumer Name:")
                </td>
                <td>
                    @Html.DisplayTextFor(m => m.OrderInfo.CustomerName)
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("Costumer Type:")
                </td>
                <td>
                    @Html.DisplayTextFor(m => m.OrderInfo.CustomerType)
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("Order Number:")
                </td>
                <td>
                    @Html.DisplayTextFor(m => m.OrderInfo.OrderNumber)
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("Total Price:")
                </td>
                <td>
                    @Html.DisplayTextFor(m => m.OrderInfo.TotalPrice)
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("Total Number of Items:")
                </td>
                <td>
                    @Html.DisplayTextFor(m => m.OrderInfo.TotalNumberOfItems)
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("Assignee:")
                </td>
                <td>
                    @Html.DisplayTextFor(m => m.OrderInfo.Assignee)
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("Date of Ordering:")
                </td>
                <td>
                    @orderingDate
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("Preferable Delivery Date:")
                </td>
                <td>
                    @preferableDeliveryDate
                </td>
            </tr>
        </table>
        <table cellspacing="20" align="right">
            <tr>
                <td>
                    @Html.Label("Status: ")
                </td>
                <td>
                    @Html.CheckBoxFor(m => m.OrderInfo.IsOrdered, new { onchange = "disable()" })
                    @Html.Label("Ordered")
                    @Html.CheckBoxFor(m => m.OrderInfo.IsDelivered, new { onchange = "disable()" })
                    @Html.Label("Delivered")
                </td>
            </tr>
            <tr>
                <td>
                    @Html.Label("Delivery Date: ")
                </td>
                <td>
                    @Html.TextBoxFor(m => m.OrderInfo.DeliveryDate, new { onchange = "disable()", id="Date", style = "width:65px; text-align:right" })
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    @Html.CheckBoxFor(m => m.OrderInfo.IsGift, new { onchange = "disable()" })
                    @Html.Label("Gift")
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <p> @Html.ValidationMessage("CheckBoxError", @"Unsupport CheckBox selection !!! Please try again !")</p>
                     <p>@Html.ValidationMessage("IncorrectDate", @"Delivery Date is incorrect !!! Please try again !")</p>
                     <p>@Html.ValidationMessage("NullDate", @"Delivery Date field is empty or incorrect !!! Please select date !")</p>
                </td>
            </tr>
        </table>
    </fieldset>
    
    <div align="right">
        <input type="submit" value="Save" name="Action" />
        <input type="submit" value="Order" name="Action" id="order" @disabled />
        <input type="submit" value="Cancel" name="Action" />
    </div>
}
<script type="text/javascript">

    function disable() {
        document.getElementById("order").disabled = true;
    }
    $(document).ready(function () {
        $('#Date').datepicker({ firstDay: 1, dateFormat: 'dd.mm.yy' });
        $('.datePicker').datepicker({ firstDay: 1, dateFormat: 'dd.mm.yy' });
    });
        
</script>
